package com.edu.bean;


import java.util.List;

/**
 * @Auther:zzp
 * @Date:2025/9/19-15:17:45
 */
public class Page<T> {

    private List<T> data;

    private int pageNum;

    private int pageSize;

    private int totalRows;

    private int totalPages;

    private boolean hasNext;

    private boolean hasPrev;

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public boolean isHasNext() {
        return hasNext;
    }

    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }

    public boolean isHasPrev() {
        return hasPrev;
    }

    public void setHasPrev(boolean hasPrev) {
        this.hasPrev = hasPrev;
    }

    public Page(List<T> data, int pageNum, int pageSize, int totalRows) {
        this.data = data;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.totalRows = totalRows;
        this.totalPages = totalRows % pageSize == 0 ? (totalRows/pageSize):(totalRows/pageSize)+1;
        if(pageNum <= 1) {
            this.hasPrev = false;
        }else {
            this.hasPrev = true;
        }

        if(pageNum>=totalPages) {
            this.hasNext = false;
        }else {
            this.hasNext = true;
        }
    }

    public Page() {
    }

    @Override
    public String toString() {
        return "Page{" +
                "data=" + data +
                ", pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", totalRows=" + totalRows +
                ", totalPages=" + totalPages +
                ", hasNext=" + hasNext +
                ", hasPrev=" + hasPrev +
                '}';
    }
}
